<template>
  <div class="login">
    <el-form v-model="LoginForm" ref="form"  label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="LoginForm.username" clearable></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="LoginForm.password" clearable ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login" >登录</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>




<script>
  import Router from "@/router";

  export default {
    data(){
      return{
        LoginForm:{
          username: '',
          password: '',

        }
      }
    },
    methods: {
      async login() {
        let url = 'http://124.223.83.80:8082/api/Login';
        const {data:res} = await this.$ajax.post(url,this.LoginForm)
        if (res.code == 200) {
          this.$msg.success(res.msg);
          // 存到sessionStorage
          window.sessionStorage.setItem('token',res.token)
          //跳转到首页
          this.$router.push('/')
        } else {
          this.$msg.error(res.msg);
        }
      },
    },
  }
</script>


<style scoped>
  .login {
    width: 500px;
    margin: 0 auto;
    margin-top: 200px;
  }
  body {
    background-color: #f0f2f5;
  }
</style>